import { ConfigManager } from "../../../com/gengine/resource/ConfigManager";
import { ChangeHeadIconInfo } from "./info/ChangeHeadIconInfo";
import { ESex } from "../../../Message/Public/ESex";
import { CutDataUtil } from "../../common/tools/CutDataUtil";
type int = number;
//class ChangeHeadIconConfig
    
    export  class ChangeHeadIconConfig
    {
        constructor()
        {
            
            this._nameDic = new Map<any, any> /* flash.utils.Dictionary */();
            this._manNorArr = [];
            this._womanNorArr = [];
            this._manSpeArr = [];
            this._womanSpeArr = [];
            this._manLoveArr = [];
            this._womanLoveArr = [];
            this._idDic = new Map<any, any> /* flash.utils.Dictionary */();
            this._avatarIdDic = new Map<any, any> /* flash.utils.Dictionary */();
            if (ChangeHeadIconConfig._instance != null) 
            {
                throw new Error(" ChangeHeadIconConfig 单例 ");
            }
            this.init();
            return;
        }

        public init(): void
        {
            var loc1=ConfigManager.instance.getJSONByFileName("t_avatar_config.json");
            this.writeUpdate(loc1);
            return;
        }

        /* internal  */writeUpdate(arg1: Object): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=arg1;
            for(loc2 of loc4) 
            {
                loc1 = new ChangeHeadIconInfo();
                loc1.avatarid = loc2.avatarid;
                loc1.code = loc2.code;
                loc1.name = loc2.name;
                loc1.sex = loc2.sex;
                loc1.type = loc2.type;
                loc1.oppositeId = loc2.oppositeId;
                loc1.addAttr = loc2.addAttr;
                if ((loc1.sex == ESex._ESexMan || loc1.sex == -1) && loc1.type == 1) 
                {
                    this._manNorArr.push(loc1.avatarid);
                }
                if ((loc1.sex == ESex._ESexWoman || loc1.sex == -1) && loc1.type == 1) 
                {
                    this._womanNorArr.push(loc1.avatarid);
                }
                if ((loc1.sex == ESex._ESexMan || loc1.sex == -1) && loc1.type == 2) 
                {
                    this._manSpeArr.push(loc1.avatarid);
                }
                if ((loc1.sex == ESex._ESexWoman || loc1.sex == -1) && loc1.type == 2) 
                {
                    this._womanSpeArr.push(loc1.avatarid);
                }
                if ((loc1.sex == ESex._ESexMan || loc1.sex == -1) && loc1.type == 3) 
                {
                    this._manLoveArr.push(loc1.avatarid);
                }
                if ((loc1.sex == ESex._ESexWoman || loc1.sex == -1) && loc1.type == 3) 
                {
                    this._womanLoveArr.push(loc1.avatarid);
                }
                this._nameDic[loc1.avatarid] = loc1.name;
                this._idDic[loc1.code] = loc1;
                this._avatarIdDic[loc1.avatarid] = loc1;
            }
            return;
        }

        public isNormalIcon(arg1: int, arg2: int): Boolean
        {
            var loc1=false;
            var loc2=0;
            var loc3=0;
            if (arg1 == 0) 
            {
                return true;
            }
            if (arg2 == ESex._ESexMan) 
            {
                loc2 = 0;
                while (loc2 < this._manNorArr.length) 
                {
                    if (arg1 == this._manNorArr[loc2]) 
                    {
                        loc1 = true;
                        break;
                    }
                    ++loc2;
                }
                return loc1;
            }
            loc3 = 0;
            while (loc3 < this._womanNorArr.length) 
            {
                if (arg1 == this._womanNorArr[loc3]) 
                {
                    loc1 = true;
                    break;
                }
                ++loc3;
            }
            return loc1;
        }

        public isSpecialIcon(arg1: int, arg2: int): Boolean
        {
            var loc1=false;
            var loc2=0;
            var loc3=0;
            if (arg2 == ESex._ESexMan) 
            {
                loc2 = 0;
                while (loc2 < this._manSpeArr.length) 
                {
                    if (arg1 == this._manSpeArr[loc2]) 
                    {
                        loc1 = true;
                        break;
                    }
                    ++loc2;
                }
                return loc1;
            }
            loc3 = 0;
            while (loc3 < this._womanSpeArr.length) 
            {
                if (arg1 == this._womanSpeArr[loc3]) 
                {
                    loc1 = true;
                    break;
                }
                ++loc3;
            }
            return loc1;
        }

        public isLoverIcon(arg1: int, arg2: int): Boolean
        {
            var loc1=false;
            var loc2=0;
            var loc3=0;
            if (arg2 == ESex._ESexMan) 
            {
                loc2 = 0;
                while (loc2 < this._manLoveArr.length) 
                {
                    if (arg1 == this._manLoveArr[loc2]) 
                    {
                        loc1 = true;
                        break;
                    }
                    ++loc2;
                }
                return loc1;
            }
            loc3 = 0;
            while (loc3 < this._womanLoveArr.length) 
            {
                if (arg1 == this._womanLoveArr[loc3]) 
                {
                    loc1 = true;
                    break;
                }
                ++loc3;
            }
            return loc1;
        }

        public getHeadIconName(arg1: int): string
        {
            return this._nameDic[arg1];
        }

        public getHeadIconId(arg1: int): ChangeHeadIconInfo
        {
            return this._idDic[arg1];
        }

        public getInfoByAvatarID(arg1: int): ChangeHeadIconInfo
        {
            return this._avatarIdDic[arg1];
        }

        public getSingleHeadAddValue(arg1: int): Array<any>
        {
            var loc1=[];
            if (this._avatarIdDic[arg1]) 
            {
                loc1 = CutDataUtil.getObjKeyValueArr((this._avatarIdDic[arg1] as ChangeHeadIconInfo).addAttr);
            }
            return loc1;
        }

        public getAllHeadAddValue(arg1: Array<any>): Map<any, any> /* flash.utils.Dictionary */
        {
            var loc7=null;
            var loc1=new Map<any, any> /* flash.utils.Dictionary */();
            var loc2=arg1.length;
            var loc3=[];
            var loc4=[];
            var loc5=0;
            while (loc5 < loc2) 
            {
                if (arg1[loc5] != 0) 
                {
                    loc3 = this.getSingleHeadAddValue(arg1[loc5]);
                    loc4 = loc4.concat(loc3);
                }
                ++loc5;
            }
            var loc6=loc4.length;
            var loc8=0;
            while (loc8 < loc6) 
            {
                loc7 = loc4[loc8];
                if (loc1[loc7.key]) 
                {
                    loc1[loc7.key] = loc1[loc7.key] + loc7.value;
                }
                else 
                {
                    loc1[loc7.key] = loc7.value;
                }
                ++loc8;
            }
            return loc1;
        }

        public static get instance(): ChangeHeadIconConfig
        {
            if (ChangeHeadIconConfig._instance == null) 
            {
                ChangeHeadIconConfig._instance = new ChangeHeadIconConfig();
            }
            return ChangeHeadIconConfig._instance;
        }

        /* internal */ /* var */_nameDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_manNorArr: Array<any>;

        /* internal */ /* var */_womanNorArr: Array<any>;

        /* internal */ /* var */_manSpeArr: Array<any>;

        /* internal */ /* var */_womanSpeArr: Array<any>;

        /* internal */ /* var */_manLoveArr: Array<any>;

        /* internal */ /* var */_womanLoveArr: Array<any>;

        /* internal */ /* var */_idDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_avatarIdDic: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ static /* var */_instance: ChangeHeadIconConfig;
    }
